// pages/service/service.js
Page({
    data: {
      activeTab: 0, // 0=在线客服, 1=常见问题, 2=意见反馈
      currentCategory: 0,
      isLoading: true,
      feedbackContent: '',
      feedbackContact: '',
      feedbackLoading: false
    },
  
    onLoad() {
    },
  
    // 切换标签
    switchTab(e) {
        console.log(e);
      this.setData({
        activeTab: e.currentTarget.dataset.index
      });
    },
  
  
    // 输入反馈内容
    onFeedbackContentInput(e) {
      this.setData({
        feedbackContent: e.detail.value
      });
    },
  
    // 输入联系方式
    onFeedbackContactInput(e) {
      this.setData({
        feedbackContact: e.detail.value
      });
    },
  
    // 提交意见反馈
    submitFeedback() {
      const { feedbackContent, feedbackContact } = this.data;
      
      if (!feedbackContent) {
        wx.showToast({
          title: '请输入反馈内容',
          icon: 'none'
        });
        return;
      }
      
      this.setData({ feedbackLoading: true });
      
      wx.cloud.callFunction({
        name: 'submitFeedback',
        data: {
          content: feedbackContent,
          contact: feedbackContact,
          userId: wx.getStorageSync('userInfo')._id
        },
        success: (res) => {
          this.setData({
            feedbackContent: '',
            feedbackContact: '',
            feedbackLoading: false
          });
          
          wx.showToast({
            title: '反馈提交成功',
            icon: 'success'
          });
        },
        fail: (err) => {
          console.error('提交反馈失败:', err);
          wx.showToast({
            title: '提交失败，请重试',
            icon: 'none'
          });
          this.setData({ feedbackLoading: false });
        }
      });
    },
  
    // 打开在线客服
    handleContact(e){
        console.log(e);
    }
  });